﻿package net.wangit.demo.i18n;

import net.wangit.Visitor;
import net.wangit.context.ActionContext;
import net.wangit.support.Action;
import net.wangit.util.StringUtil;

public class ChangeLocaleAction implements Action {

  public ActionContext execute(ActionContext ac) throws Exception {
    String locale = ac.getRequestParameter("i18n.locale");
    ac.setSessionAttribute("demo.i18n.locale", locale);
    String[] params = StringUtil.split(locale, "_");
    Visitor visitor = ac.getVisitor();
    visitor.setLanguage(params[0]);
    if (params.length > 1) {
      visitor.setCountry(params[1]);
    } else {
      visitor.setCountry(null);
    }    
    return ac;
  }

}
